/**
 * Copyright 2015 Qiyi Inc. All rights reserved.
 * 
 * @file:   Channel.Config.js
 * @path:   js-src/Channel/
 * @desc:   Channel公共配置集合，键值对象
 *          一级键名大写，之间名采用驼峰式
 * @author: jiegang@qiyi.com
 * @date:   2015-01-10
 */
///import js-src/lib/
///import js-src/com/
qui(function(require, exports, module) {
    Stream.Config = $.extend({}, Ancestor.Config, {

        STREAM_FORM: {

            rules: {
                peerCount: {
                    required: true,
                    min: 1
                },


            },


            messages: {
                "peerCount": {
                    "required": "镜像服务器数不能为空",
                    "min": "镜像服务器数不能小于1"

                },
            }

        },

        // 修改前数据
        BEFORE_DATA: null,

        // 编码状态
        STATUS: {},

        // 码流清晰度
        TYPE: {},

        // 地区
        DEST: {},

        CUTTER_ID: {
            FLV: [],
            TS: []
        },

        TABLE_COLMODEL_CONFIG: {
            /*
                id: {                    name: 'id',
                    index:'id',
                    title: false,
                    width: 50,
                    align: 'center',
                    sortable: false
                },*/
            channelName: {
                name: 'channelName',
                index: 'channelName',
                title: false,
                width: 70,
                align: 'center',
                sortable: false
            },
            streamName: {
                name: 'streamName',
                index: 'streamName',
                width: 80,
                title: false,
                align: 'center',
                sortable: false,
                formatter: function(v, o, r) {
                    return Stream.Util.formatter.streamName(v, r);
                }
            },

            streamIp: {
                name: 'streamIp',
                index: 'streamIp',
                width: 90,
                title: false,
                align: 'center',
                sortable: false,
                formatter: function(v, o, r) {
                    return Stream.Util.formatter.streamIp(v, r);
                }

            },

            encodedIp: {
                name: 'encodedIp',
                index: 'encodedIp',
                width: 80,
                title: false,
                align: 'center',
                sortable: false,
                formatter: function(v, o, r) {
                    return Stream.Util.formatter.encodedIp(v, r);
                }
            },

            inputSignal: {
                name: 'inputSignal',
                index: 'encodedIp',
                width: 80,
                title: false,
                align: 'center',
                sortable: false,
                formatter: function (v, o, r) {
                    return Stream.Util.formatter.inputSignal(v, r);
                }
            },

            dolbySignal: {
              name: 'dolbySignal',
                index: 'dolbySignal',
                width: 80,
                title: false,
                align: 'center',
                sortable: false,
                formatter: function(v, o, r) {
                    return Stream.Util.formatter.dolbySignal(v, r);
                }
            },

            dest: {
                name: 'dest',
                index: 'dest',
                width: 40,
                title: false,
                align: 'center',
                sortable: false,
                formatter: function(v, o, r) {
                    return Stream.Util.formatter.dest(v, r);
                }
            },

            streamType: {
                name: 'streamType',
                index: 'streamType',
                title: false,
                width: 60,
                sortable: false,
                align: 'center',
                formatter: function(v, o, r) {
                    return Stream.Util.formatter.streamType(v, r);
                }

            },

            status: {
                name: 'status',
                index: 'status',
                title: false,
                width: 60,
                sortable: false,
                align: 'center',
                formatter: function(v, o, r) {
                    return Stream.Util.formatter.status(v, r);
                }

            },

            bitRate: {
                name: 'bitRate',
                index: 'bitRate',
                title: false,
                width: 60,
                align: 'center',
                sortable: false
            },

            inputBits: {
                name: 'inputBits',
                index: 'inputBits',
                title: false,
                width: 75,
                align: 'center',
                sortable: false
            },


            outputBits: {
                name: 'outputBits',
                index: 'outputBits',
                title: false,
                width: 80,
                align: 'center',
                sortable: false
            },


            aspectRatio: {
                name: 'aspectRatio',
                index: 'aspectRatio',
                title: false,
                align: 'center',
                width: 75
            },

            frameRate: {
                name: 'frameRate',
                index: 'frameRate',
                title: false,
                align: 'center',
                width: 75
            },

            screenSize: {
                name: 'screenSize',
                index: 'screenSize',
                title: false,
                sortable: false,
                align: 'center',
                width: 75

            },
            encodeType: {
                name: 'encodeType',
                index: 'encodeType',
                title: false,
                width: 70,
                align: 'center',
                sortable: false,

                formatter: function(v, o, r) {
                    return Stream.Util.formatter.encodeType(v, r);
                }
            },

            audio: {
                name: 'audio',
                index: 'audio',
                title: false,
                width: 70,
                align: 'center',
                sortable: false
            },

            peerCount: {
                name: 'peerCount',
                index: 'peerCount',
                width: 90,
                sortable: false,
                align: 'center',
                title: false
            },

            addTime: {
                name: 'addTime',
                index: 'addTime',
                width: 120,
                sortable: false,
                align: 'center',
                title: false
            },

            updateTime: {
                name: 'updateTime',
                index: 'updateTime',
                width: 120,
                sortable: false,
                align: 'center',
                title: false
            },
            isEnable: {
                name: 'isEnable',
                index: 'isEnable',
                width: 75,
                sortable: false,
                align: 'center',

                formatter: function(v, o, r) {
                    return Stream.Util.formatter.isEnable(v, r);
                }
            },
            create: {
                name: 'create',
                width: 150,
                sortable: false,
                title: false,
                align: 'center',

                formatter: function(v, o, r) {
                    return Stream.Util.formatter.create(v, r);
                }

            },
            operate: {
                name: 'operate',
                width: 80,
                sortable: false,
                title: false,
                align: 'center',

                formatter: function(v, o, r) {
                    return Stream.Util.formatter.operate(v, r);
                }

            }

        },


        TABLE: { //素材库查询列表配置
            url: '/api/stream/list',

            loadBeforeSend: function(xhr, settings) {
                var auth = Ancestor.Util.getAuth(Ancestor.Config.EPG_AUTH.list);
                xhr.setRequestHeader('Sign', auth.sign);
                xhr.setRequestHeader("Time", auth.clientTime);
                xhr.setRequestHeader("From", auth.from);
                return true;
            },
            loadComplete: function (data) {
                data.data.forEach(function (element, index) {
                    if (element.isEnable == 1) {
                        //console.log(" sliceIndex =======  " + element.sliceIndex);
                        if (element.sliceIndex != -1) {
                            var splitUrls = element.streamUrls.split(" ");
                            if (splitUrls != null) {
                                var cutterUrl = splitUrls[element.sliceIndex];
                                if(cutterUrl != null) {
                                    var cutterUrlSplitArray = cutterUrl.split("/");
                                    var cutterUrlStreamName = cutterUrlSplitArray[cutterUrlSplitArray.length - 1];

                                    //获取线上服务器,标绿
                                    var $grid = $('#StreamListContainer').find('table.grid');
                                    var rowDataIDs = $grid.getDataIDs();
                                    $(rowDataIDs).each(function (index, eachRowDataId) {
                                            var eachRowData = $grid.getRowData(eachRowDataId);
                                            //console.log("eachRowData -------------" + JSON.stringify(eachRowData));

                                            var eachRowDataStreamSplit = eachRowData.streamName.split(">");
                                            var colStreamName = eachRowDataStreamSplit[1].split("<")[0];
                                            if (colStreamName == cutterUrlStreamName) {
                                                var newStreamData = eachRowDataStreamSplit[0] + " style=\"color:limegreen\" >" + colStreamName + "</a>"
                                                $grid.setRowData(eachRowDataId, {streamName: newStreamData});
                                            }
                                        }
                                    );
                                }
                            }
                        }
                    }
                })
            },

            //datatype:"jsonp",
            multiselect: false,
            colNames: ["频道名称", "流名称", "RTMP地址", "编码器地址", "信号源", "杜比信号源", "地区", "清晰度", "编码状态",
                "码流", "推流流速率", "下载流速率", "画面比例", "帧率",
                "画面尺寸", "视频类型", "音频类型", "镜像服务器数", "添加时间", "最后更新时间", "上下线状态", "创建", "操作"
            ],

            colModel: ['channelName', 'streamName', 'streamIp', 'encodedIp', 'inputSignal','dolbySignal', 'dest', 'streamType', 'status',
                'bitRate', 'inputBits', 'outputBits', 'aspectRatio', 'frameRate', 'screenSize', 'encodeType', 'audio',
                'peerCount', 'addTime', 'updateTime', 'isEnable', 'create', 'operate'
            ]
        },

        // 全景直播类型
        VIDEO_TYPE: {},

        // 3D直播参数
        THREE_D_VIDEO_TYPE: {
            "1": "普通视频",
            "2": "偏振(左右)3D格式",
            "3": "红蓝3D格式",
            "4": "上下3D格式",
        },

        // 流列表信息
        STREAMS_INFO: {},

        // 频道信息
        CHANNEL_INFO: null,

        // 流状态查询
        STREAM_SPAN: {
            "flv": 'http://cutteradmin.qiyi.domain:7777/statchannel?ch={channelName}&user=ppslive&src_type=PPC&version=2.0',
            "ts": 'http://cutteradmin.qiyi.domain:7777/statm3u8_ts?ch={channelName}&user=ppslive&src_type=PPC&version=2.0',
            "newts": 'http://cutteradmin.qiyi.domain:7777/stathttp2ts?ch={channelName}&user=ppslive&src_type=PPC&version=2.0',
            "dolby": 'http://cutteradmin.qiyi.domain:7777/stathttp2ts?ch={channelName}&user=ppslive&src_type=PPC&version=2.0'
        },

        STREAM_API_VERSION: {
            "0": '1.2',
            "1": '2.0'
        },

        // 码流信息(分辨率， 视频码率， 音频码率， 比例)
        STREAM_TYPE_INFO: {
            // stream_type, resolution, video_rate, audio_rate, video_ratio
            "TOP_SPEED": ['200p', '640x360', '200k', '32', '16:9'],
            "SMOOTH": ['360p', '640x360', '400k', '48', '16:9'],
            "HIGH_DEFINITION": ['540p', '960x540', '800k', '64', '16:9'],
            "RESOLUTION_720P": ['720p', '1280x720', '1.2m', '64', '16:9'],
            "RESOLUTION_1080P": ['1080p', '1920x1080', '2.0m', '128', '16:9'],
            "RESOLUTION_2K": ['2K', '2560x1440', '5.0m', '256', '16:9'],
            "RESOLUTION_4K": ['4K', '3840x2160', '6.0m', '256', '16:9']
        },

        ENCODER_CONFIG: (function() {
            var prefix = auth.dev() ? 'http://10.77.44.136:50001/dispatch/' : 'http://lunbodisp.live.qiyi.domain/dispatch/';
            return {
                encoder_close: prefix + "close",
                encoder_state: prefix + "state",
                encoder_start: prefix + "start",
                liveType_lb: '3'
            }
        })(),
        VRS_DATA:null,

        CUTTERINFO_URL: {
            'FLV': 'http://cutteradmin.qiyi.domain:7777/channelusage?user=ppscroot',
            'TS': 'http://cutteradmin.qiyi.domain:7777/m3u8_tsusage?user=ppscroot',
        },
        VRS_CONFIG:{
            S_SRC_13:"03032001010000000000",
            S_SRC_15:"02020031010000000000",
            BASE_FREE_URL:"http://live.video.iqiyi.com/live?k_uidgtzzvy7f4defxriu2jiqcclojibbczdj",
            BASE_VIP_URL:"http://port.qiyi.com/live/vip/ts"
        }

        //        ENCODER_CONFIG: {
        //
        //          encoder_start : 'http://10.23.70.35:50001/dispatch/start?channelid=${channelid}&encoder=abcd&obj=rtmp://10.121.86.127/live/xiang&progid=375544100',
        //          encoder_close : auth.dev() ? 'http://10.23.70.35:50001/dispatch/close' : 'http://lunbodisp.live.qiyi.domain/dispatch/close',
        //          encoder_state : auth.dev() ? 'http://10.23.70.35:50001/dispatch/state' : 'http://lunbodisp.live.qiyi.domain/dispatch/state',
        //          encoder_start : auth.dev() ? 'http://10.23.70.35:50001/dispatch/start' : 'http://lunbodisp.live.qiyi.domain/dispatch/start',
        //          liveType_lb : '3',
        //      }

    });
});